{% extends 'base.html' %}

{% block title %}生成测试报告{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header">
            <h1 class="mb-0">生成测试报告</h1>
        </div>
        <div class="card-body">
            {% if test_run %}
            <p>您正在为测试运行 <strong>{{ test_run.name }}</strong> 生成报告。</p>
            <div class="alert alert-info">
                <p><strong>项目:</strong> {{ test_run.project.name }}</p>
                <p><strong>环境:</strong> {{ test_run.environment.name }}</p>
                {% if test_run.test_suite %}
                <p><strong>测试套件:</strong> {{ test_run.test_suite.name }}</p>
                {% endif %}
                <p><strong>状态:</strong> {{ test_run.status }}</p>
                <p><strong>开始时间:</strong> {{ test_run.start_time }}</p>
                <p><strong>结束时间:</strong> {{ test_run.end_time }}</p>
            </div>
            {% elif test_suite_run %}
            <p>您正在为测试套件 <strong>{{ test_suite_run.test_suite.name }}</strong> 的运行结果生成报告。</p>
            {% endif %}
            
            <form method="post">
                {% csrf_token %}
                
                <div class="mb-3">
                    <label for="{{ form.name.id_for_label }}" class="form-label">报告名称</label>
                    {{ form.name }}
                    {% if form.name.errors %}
                    <div class="invalid-feedback d-block">
                        {{ form.name.errors }}
                    </div>
                    {% endif %}
                </div>
                
                <div class="mb-3">
                    <label for="{{ form.description.id_for_label }}" class="form-label">报告描述</label>
                    {{ form.description }}
                    {% if form.description.errors %}
                    <div class="invalid-feedback d-block">
                        {{ form.description.errors }}
                    </div>
                    {% endif %}
                </div>
                
                <div class="mb-3">
                    <label for="{{ form.report_format.id_for_label }}" class="form-label">报告格式</label>
                    {{ form.report_format }}
                    {% if form.report_format.errors %}
                    <div class="invalid-feedback d-block">
                        {{ form.report_format.errors }}
                    </div>
                    {% endif %}
                </div>
                
                <div class="mb-3 form-check">
                    {{ form.is_public }}
                    <label class="form-check-label" for="{{ form.is_public.id_for_label }}">
                        公开报告（无需登录即可查看）
                    </label>
                    {% if form.is_public.errors %}
                    <div class="invalid-feedback d-block">
                        {{ form.is_public.errors }}
                    </div>
                    {% endif %}
                </div>
                
                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-primary">生成报告</button>
                    {% if test_run %}
                    <a href="{% url 'test_run_detail' test_run.pk %}" class="btn btn-secondary">取消</a>
                    {% elif test_suite_run %}
                    <a href="{% url 'test_suite_run_detail' test_suite_run.pk %}" class="btn btn-secondary">取消</a>
                    {% endif %}
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 添加表单样式
        document.getElementById('id_name').classList.add('form-control');
        document.getElementById('id_description').classList.add('form-control');
        document.getElementById('id_report_format').classList.add('form-select');
        document.getElementById('id_is_public').classList.add('form-check-input');
    });
</script>
{% endblock %}
